import { ADD, ADDNUM, REDUCE, REDUCENUM } from '../types'

import { Map } from 'immutable'

const reducer = (state = Map({
  count: 100
}), action) => {

  switch (action.type) {
    case ADD:
      // return { ...state, count: state.count + 1 }
      return state.set('count', state.get('count') + 1)

    case ADDNUM:
      // return { ...state, count: state.count + action.payload }
      return state.set('count', state.get('count') + action.payload)

    case REDUCE:
      // return { ...state, count: state.count - 1 }
      return state.set('count', state.get('count') - 1)

    case REDUCENUM:
      // return { ...state, count: state.count - action.payload }
      return state.set('count', state.get('count') - action.payload)

    default:
      return state
  }
}

export default reducer
